<?php
/**
 * Created by PhpStorm.
 * User: ytlmi
 * Date: 2018/3/12
 * Time: 10:44
 */

namespace org\util\forensictool\forensicreport;

use org\util\wordtool\Table;
use org\util\forensictool\LittleTools;
use org\util\wordtool\Word;

class ReportQz extends BaseReport
{
    /**
     * @throws \Exception
     */
    protected function makeSampleTable()
    {
        $tempPage=Word::instance()->createTemp();
        $table = $tempPage->addTable(self::TABLE_STYLE);
        $roleGroup = $this->makeRoleGroup();
        $this->addRow($table,'head','first');
        if (in_array('M', $roleGroup[0])) {//添加母亲行
            $this->addRow($table,'M');
            foreach ($roleGroup[0] as $index=>$role) {
                if($role=='M') unset($roleGroup[0][$index]);
            }
        }
        foreach ($roleGroup[1] as $role) {//添加孩子行
            $this->addRow($table,$role,count($roleGroup[0])==0 ? 'last' : 'mid');
        }
        foreach ($roleGroup[0] as $index=>$role) {
            $position = isset($roleGroup[0][$index+1]) ? 'mid' : 'last';
            $this->addRow($table,$role,$position);
        }
        return $tempPage;
    }


    /**
     * @param Table $table
     * @param string $role
     * @param string $position
     * @throws \Exception
     */
    protected function addRow(Table $table, $role, $position = 'mid')
    {
        $positionMap=['first'=>self::FIRST_ROW_STYLE,'mid'=>self::MID_ROW_STYLE,'last'=>self::LAST_ROW_STYLE];
        $width = [1100, 900, 900, 900, 2500, 1800];
        if ($role == 'head') {
            $content = ['被鉴定人', '性别', '称谓', '民族', '身份证件号码', '样本编号'];
        } else {
            $content = [
                $this->caseData['samples'][$role]['person_name'],
                LittleTools::formatSex($this->caseData['samples'][$role]['person_sex']),
                LittleTools::makeZhCalling($role),
                $this->caseData['samples'][$role]['person_race'],
                $this->caseData['samples'][$role]['person_id'],
                $this->caseData['samples'][$role]['sample_name']
            ];
        }
        $table->addSimpleRow($content, $width, self::TABLE_FONT, $positionMap[$position]);
    }



    protected function makeDetectionTable(){}

    protected function makeDescribe(){}
}